<template>
<div>
    <el-form :model="inputForm" ref="inputForm" v-loading="loading"   :disabled="formReadOnly"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="24">
            <el-form-item label="物料编码" prop="materialCode"
                :rules="[
                 ]">
              <el-input v-model="inputForm.materialCode" placeholder="请填写物料编码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="物料名称" prop="materialName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.materialName" placeholder="请填写物料名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="规格型号" prop="specificationsModel"
                :rules="[
                 ]">
              <el-input v-model="inputForm.specificationsModel" placeholder="请填写规格型号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="计量单位" prop="measurementUnit"
                :rules="[
                 ]">
              <el-input v-model="inputForm.measurementUnit" placeholder="请填写计量单位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="使用单位" prop="useUnit"
                :rules="[
                 ]">
              <el-input v-model="inputForm.useUnit" placeholder="请填写使用单位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="ABC分类" prop="letterClassification"
                :rules="[
                 ]">
              <el-input v-model="inputForm.letterClassification" placeholder="请填写ABC分类"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="数量" prop="number"
                :rules="[
                 ]">
              <el-input v-model="inputForm.number" placeholder="请填写数量"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="单价" prop="unitPrice"
                :rules="[
                 ]">
              <el-input v-model="inputForm.unitPrice" placeholder="请填写单价"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="金额" prop="amount"
                :rules="[
                 ]">
              <el-input v-model="inputForm.amount" placeholder="请填写金额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="库存数量" prop="libraryNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.libraryNumber" placeholder="请填写库存数量"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="成本中心" prop="costCenter"
                :rules="[
                 ]">
              <el-input v-model="inputForm.costCenter" placeholder="请填写成本中心"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="登记人" prop="registrarPeople"
                :rules="[
                 ]">
              <el-input v-model="inputForm.registrarPeople" placeholder="请填写登记人"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="备件安装所在设备名称" prop="equipmentName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.equipmentName" placeholder="请填写备件安装所在设备名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="检修类别" prop="maintenanceCategory"
                :rules="[
                 ]">
              <el-input v-model="inputForm.maintenanceCategory" placeholder="请填写检修类别"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="安装日期" prop="installDate"
                :rules="[
                 ]">
              <el-input v-model="inputForm.installDate" placeholder="请填写安装日期"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="更换部件" prop="replaceParts"
                :rules="[
                 ]">
              <el-input v-model="inputForm.replaceParts" placeholder="请填写更换部件"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="原更换日期" prop="originalReplaceDate"
                :rules="[
                 ]">
              <el-input v-model="inputForm.originalReplaceDate" placeholder="请填写原更换日期"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="安装人工号" prop="installWorkNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.installWorkNumber" placeholder="请填写安装人工号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="更换工时" prop="replaceWorkDate"
                :rules="[
                 ]">
              <el-input v-model="inputForm.replaceWorkDate" placeholder="请填写更换工时"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="安装人姓名" prop="installWorkName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.installWorkName" placeholder="请填写安装人姓名"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="更换原因" prop="replaceWhy"
                :rules="[
                 ]">
              <el-input v-model="inputForm.replaceWhy" placeholder="请填写更换原因"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
</div>
</template>

<script>
  export default {
    data () {
      return {
        title: '',
        method: '',
        loading: false,
        inputForm: {
          id: '',
          materialCode: '',
          materialName: '',
          specificationsModel: '',
          measurementUnit: '',
          useUnit: '',
          letterClassification: '',
          number: '',
          unitPrice: '',
          amount: '',
          libraryNumber: '',
          costCenter: '',
          registrarPeople: '',
          equipmentName: '',
          maintenanceCategory: '',
          installDate: '',
          replaceParts: '',
          originalReplaceDate: '',
          installWorkNumber: '',
          replaceWorkDate: '',
          installWorkName: '',
          replaceWhy: ''
        }
      }
    },
    props: {
      businessId: {
        type: String,
        default: ''
      },
      formReadOnly: {
        type: Boolean,
        default: false
      }
    },
    components: {
    },
    watch: {
      'businessId': {
        handler (newVal) {
          if (this.businessId) {
            this.init(this.businessId)
          } else {
            this.$nextTick(() => {
              this.$refs.inputForm.resetFields()
            })
          }
        },
        immediate: true,
        deep: false
      }
    },
    methods: {
      init (id, row) {
        // if (id) {
        //   this.loading = true
        //   this.inputForm.id = id
        //   this.$nextTick(() => {
        //     this.$refs.inputForm.resetFields()
        //     this.$http({
        //       url: `/spareparts/material/sparepartsOutLibraryRegistration/queryById?id=${this.inputForm.id}`,
        //       method: 'get'
        //     }).then(({data}) => {
        //       this.inputForm = this.recover(this.inputForm, data.sparepartsOutLibraryRegistration)
        //       this.loading = false
        //     })
        //   })
        // }
      },
      // 表单提交
      saveForm (callback) {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/spareparts/material/sparepartsOutLibraryRegistration/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              if (data && data.success) {
                callback(data.businessTable, data.businessId)
              }
            })
          }
        })
      }
    }
  }
</script>
